
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;


entity onepwmc is
generic (N1:integer:=1000000;
		M1:integer:=20000);
port (
		angle:in std_logic_vector (9 downto 0);--nine bits representing 256,we use only use 0~180,each number representing a degree.
		--pf0-pf9
		validate:	in std_logic;
		--pf10
		addr:in std_logic_vector (2 downto 0);--which pwm controller we want to program.
		--pc0-pc2
		clk:in std_logic;					--system clock	
		outp:out std_logic_vector (7 downto 0)--output to upto 8 servo motors.
		);
end entity;

architecture a of onepwmc is
	type buf is array (0 to 7) of integer ;
	signal temp:integer range N1 downto 0;
	shared variable buff:buf:=(75000,75000,75000,75000,75000,75000,75000,75000) ;
begin


ValidateProcess:process (validate)---clock the value in
begin
	if  rising_edge(validate) then
	buff(conv_integer(addr)):=conv_integer(angle );
	end if;
end process;

RollingProcess:process (clk)	----let's roll
begin
	if rising_edge(clk) then
		if temp=N1-1 then temp<=0;
		else temp<=temp+1;
		end if;
	end if;
end process;
		outp(0)<='1'  when temp<buff(0) else '0';
		outp(1)<='1'  when temp<buff(1) else '0';
		outp(2)<='1'  when temp<buff(2) else '0';
		outp(3)<='1'  when temp<buff(3) else '0';
		outp(4)<='1'  when temp<buff(4) else '0';
		outp(5)<='1'  when temp<buff(5) else '0';
		outp(6)<='1'  when temp<buff(6) else '0';
		outp(7)<='1'  when temp<buff(7) else '0';
end a;